package com.yy.wga.admin.service.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yy.wga.mp.common.interceptor.RequestUserHolder;
import com.yy.wga.mp.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.module.admin.request.AdminIncomeWithdrawSettingSaveRequest;
import com.yy.wga.mp.module.admin.response.AdminIncomeWithdrawSettingInfoResponse;
import com.yy.wga.mp.module.income.entity.pojo.IncomeWithdrawSettingDO;
import com.yy.wga.mp.module.income.service.IncomeWithdrawSettingService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 运营后台/提现设置
 *
 * @author guochao
 * @since 2024-11-10 21:10:23
 */
@RestController
@RequestMapping("admin/income/withdrawSetting")
public class AdminIncomeWithdrawSettingController {
    /**
     * 服务对象
     */
    @Resource
    private IncomeWithdrawSettingService incomeWithdrawSettingService;

    /**
     * 查询
     * @return
     */
    @GetMapping("get")
    public Result<AdminIncomeWithdrawSettingInfoResponse> get() {
        IncomeWithdrawSettingDO incomeWithdrawSetting = incomeWithdrawSettingService.getOne(new LambdaQueryWrapper<IncomeWithdrawSettingDO>()
                .eq(IncomeWithdrawSettingDO::getAppKey, RequestUserHolder.getBaseRequest().getAppKey()));
        return Result.success(BeansUtils.map(incomeWithdrawSetting, AdminIncomeWithdrawSettingInfoResponse.class));
    }

    /**
     * 保存
     * @param request
     * @return
     */
    @PostMapping("save")
    public Result<Boolean> save(@Valid @RequestBody AdminIncomeWithdrawSettingSaveRequest request) {
        IncomeWithdrawSettingDO incomeWithdrawSetting = BeansUtils.map(request, IncomeWithdrawSettingDO.class);
        incomeWithdrawSetting.setAppKey(RequestUserHolder.getBaseRequest().getAppKey());
        incomeWithdrawSettingService.saveOrUpdate(incomeWithdrawSetting);
        return Result.success(Boolean.TRUE);
    }
}
